//
//  HOPBaseController.swift
//  WB01
//
//  Created by HOP on 15/12/15.
//  Copyright © 2015年 HOP. All rights reserved.
//

import UIKit

class HOPBaseController: UITableViewController, HOPVisitorViewDelegate {

    var isLogin = HOPuserAccount.userLogin
    override func viewDidLoad() {
        super.viewDidLoad()
        isLogin ? super.loadView() : setupVisitorView()
    }
    private func setupVisitorView() {
        
//    let visitorView = HOPVisitorController()
        
        view = visitorView
        visitorView.visitorViewDelegate = self
        if self is HOPHomeController {
        visitorView.startRotationAnimation()
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "didBecomeActive", name: UIApplicationDidEnterBackgroundNotification, object: nil)
        }else if self is HOPMessageController {
        visitorView.setupInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        didEnterBackground()
        }else if self is HOPDiscoverController {
            visitorView.setupInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
            didEnterBackground()
        }else if self is HOPProfileController {
            visitorView.setupInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
            didEnterBackground()
        }
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitouViewRegister")
       navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewLogin")
        
            }
    deinit {
        // 移除通知
        if self is HOPHomeController {
            NSNotificationCenter.defaultCenter().removeObserver(self)

        }
       
    }
    /// 应用进入后台会调用
    func didEnterBackground() {
        // 暂停核心动画
    visitorView.pauseAnimation()
    }
    /// 进入应用程序
    func didBecomeActive() {
        // 开始核心动画
    visitorView.resumeAnimation()
    
    }
    // MARK: - 懒加载
    /// 访客视图
    private lazy var visitorView: HOPVisitorController = HOPVisitorController()
    //代理实现方法
    func visitorViewLogin() {
      // 创建登陆界面
        let oauthVC = HOPOauthViewController()
        // 弹出登陆界面,包装导航控制器
        presentViewController(UINavigationController(rootViewController: oauthVC), animated: true, completion: nil)
    }
    func visitouViewRegister() {
        print(__FUNCTION__)
    }
    }
